package com.tzpay.tzpay.api;

import android.text.TextUtils;

import com.tzpay.tzpay.bean.OrderInfo;
import com.tzpay.tzpay.bean.UserInfo;
import com.tzpay.tzpay.common.ConstValue;
import com.tzpay.tzpay.utils.TzCryptTool;
import com.tzpay.tzpay.utils.Utils;

/**
 * Created by Yax.
 * Date: 16/3/30
 * Time: 下午2:53
 * Description: 上传交易流水
 */
public class UploadOrderRequest {

    String shopId = UserInfo.getInstance().getShopId();//商户编号
    String funcId = UserInfo.getInstance().getFuncId();//支付方式
    String txCode;//交易类型:DO:消费扣款，RNC:退款
    String txTime;//交易时间 2015-01-01 12:12:11
    String userID = UserInfo.getInstance().getUserName();//操作员ID
    String deviceId = ConstValue.DEVICE_ID;//设备号
    String merchantId = UserInfo.getInstance().getMerchantNo();
    String orderNo;
    String orderReqNo;
    String orderDate;
    String ourTransNo;
    String transAmt;
    String transStatus;
    String refundFlag;
    String customerID;
    String mac;//MD5加密

    public String getShopId() {
        return shopId;
    }

    public void setShopId(String shopId) {
        this.shopId = shopId;
    }

    public String getFuncId() {
        return funcId;
    }

    public void setFuncId(String funcId) {
        this.funcId = funcId;
    }

    public String getTxCode() {
        return txCode;
    }

    public void setTxCode(String txCode) {
        this.txCode = txCode;
    }

    public String getTxTime() {
        return txTime;
    }

    public void setTxTime(String txTime) {
        this.txTime = txTime;
    }

    public String getUserID() {
        return userID;
    }

    public void setUserID(String userID) {
        this.userID = userID;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(String merchantId) {
        this.merchantId = merchantId;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getOrderReqNo() {
        return orderReqNo;
    }

    public void setOrderReqNo(String orderReqNo) {
        this.orderReqNo = orderReqNo;
    }

    public String getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(String orderDate) {
        this.orderDate = orderDate;
    }

    public String getOurTransNo() {
        return ourTransNo;
    }

    public void setOurTransNo(String ourTransNo) {
        this.ourTransNo = ourTransNo;
    }

    public String getTransAmt() {
        return transAmt;
    }

    public void setTransAmt(String transAmt) {
        this.transAmt = transAmt;
    }

    public String getTransStatus() {
        return transStatus;
    }

    public void setTransStatus(String transStatus) {
        this.transStatus = transStatus;
    }

    public String getRefundFlag() {
        return refundFlag;
    }

    public void setRefundFlag(String refundFlag) {
        this.refundFlag = refundFlag;
    }

    public String getCustomerID() {
        return customerID;
    }

    public void setCustomerID(String customerID) {
        this.customerID = customerID;
    }

    public String getMac() {
        return mac;
    }

    public void setMac(String mac) {
        this.mac = mac;
    }

    @Override
    public String toString() {
        return "UploadOrderRequest{" +
                "shopId='" + shopId + '\'' +
                ", funcId='" + funcId + '\'' +
                ", txCode='" + txCode + '\'' +
                ", txTime='" + txTime + '\'' +
                ", userID='" + userID + '\'' +
                ", deviceId='" + deviceId + '\'' +
                ", merchantId='" + merchantId + '\'' +
                ", orderNo='" + orderNo + '\'' +
                ", orderReqNo='" + orderReqNo + '\'' +
                ", orderDate='" + orderDate + '\'' +
                ", ourTransNo='" + ourTransNo + '\'' +
                ", transAmt='" + transAmt + '\'' +
                ", transStatus='" + transStatus + '\'' +
                ", refundFlag='" + refundFlag + '\'' +
                ", customerID='" + customerID + '\'' +
                ", mac='" + mac + '\'' +
                '}';
    }

    /**
     * 由OrderInfo构建UploadOrderRequest
     * @param info
     * @return
     */
    public static UploadOrderRequest buildUploadOrderRequest(OrderInfo info) {
        if (info == null) {
            return null;
        }
        /**
         String txCode;//交易类型:DO:消费扣款，RNC:退款
         String txTime;//交易时间 2015-01-01 12:12:11
         String userID = UserInfo.getInstance().getUserName();//操作员ID
         String deviceId = ConstValue.DEVICE_ID;//设备号
         String merchantId = UserInfo.getInstance().getMerchantNo();
         String orderNo;
         String orderReqNo;
         String orderDate;
         String ourTransNo;
         String transAmt;
         String transStatus;
         String refundFlag;
         String customerID;
         String mac;//MD5加密
         */
        UploadOrderRequest request = new UploadOrderRequest();
        request.setTxTime(Utils.formatTime(info.getOrderDate())); // yyyyMMddhhmmss
        request.setTxCode(info.getTxCode());
        request.setOrderNo(info.getOrderNo());
        request.setOrderReqNo(info.getOrderReqNo());
        request.setOrderDate(info.getOrderDate());
        request.setOurTransNo(info.getOurTransNo());
        request.setTransAmt(!TextUtils.isEmpty(info.getTransAmt()) ? info.getTransAmt() : info.getOrderAmt());
        request.setTransStatus(info.getTransStatus());
        request.setRefundFlag(info.getRefundFlag());
        request.setCustomerID(info.getCustomerId());
        request.setMac(TzCryptTool.md5ForEPay(request.getDeviceId(),
                request.getMerchantId(), request.getOrderNo(),
                request.getShopId(), request.getFuncId(),
                UserInfo.getInstance().getMerchantKey()));
        return request;
    }
}
